<?php
    $conn=mysqli_connect('localhost','root','root','school') or die('连接失败');
    $book_name=$_POST['book_name'];
    if (empty($book_name)){
        $sql="select * from book;";
    }else{
        $sql="select * from book where book_name like '%$book_name%';";
    }
    $mq=mysqli_query($conn,$sql);
        while($rows=mysqli_fetch_assoc($mq)){
            $books[]=$rows;
    }

//var_dump($books);
?>
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <a href="add.php">新增</a>
    <table border="1">
        <tr>
            <th>图书编号</th>
            <th>图书名称</th>
            <th>国际标准书号</th>
            <th>作者</th>
            <th>操作</th>
        </tr>
        <?php
            foreach ($books as $key) {?>
                <tr>
                    <td><?php echo $key['book_id'] ?></td>
                    <td><?php echo $key['book_name'] ?></td>
                    <td><?php echo $key['isbn'] ?></td>
                    <td><?php echo $key['author'] ?></td>
                    <td><a href="delete.php?book_id=<?php echo $key['book_id']?>">删除</a></td>
                </tr>
                <?php
        }
        ?>
    </table>
</body>
</html>
